<template>
	<view class="store">
		<view class="head" :style="{height: pHeight + tHeight + 'px'}">
			<view class="xztitle" :style="[{height: pHeight + 'px', top: tHeight + 'px',lineHeight: pHeight + 'px'}]">
				门店分配
				<view class="iconfont icon-dayuhao1" @click="fanhui"></view>
			</view>
		</view>
		<view class="headtop" :style="{marginTop: pHeight + tHeight + 'px'}">
			<view class="sousuo clearfix">
				<!-- <view class="left fl clearfix" @click="keytankuang">
					<view class="name fl">请选择</view>
					<image :src="baseUrl + '/wximage/dataxl.png'" class="fl"></image>
				</view> -->
				<view class="right fr">
					<input type="text" placeholder="请输入关键字" v-model="formData.search" @confirm="search"/>
					<image :src="baseUrl + '/wximage/sousuo.png'" @click="search"></image>
				</view>
			</view>
			
			<view class="beijing" v-if="bjstatus" @click="guanbi"></view>
			<view class="tankuang" v-if="keystatus">
				<view class="liebiao">
					<view class="wenzi">平台员工</view>
				</view>
				<view class="liebiao">
					<view class="wenzi">代理商</view>
				</view>
				<view class="liebiao">
					<view class="wenzi">商户</view>
					<image :src="baseUrl + '/wximage/shaixuanbj.png'"></image>
				</view>
				<view class="liebiao">
					<view class="wenzi">代理商员工</view>
				</view>
			</view>
		</view>
		<view class="shuju" v-for="(item,index) in stationList" :key="index" v-if="stationList.length != 0">
			<view class="li"  @click="dianji(item,index)">
				<view class="top clearfix">
					<image :src="baseUrl + '/wximage/fundbj.png'" class="fl"></image>
					<view class="cen fl">
						<text class="title">{{item.name}}</text>
						<text class="shebei">设备台数：{{item.stationsum}}</text>
					</view>
					<view class="you" v-if="item.checked==false"><image :src="baseUrl + '/wximage/weixz.png'"></image></view>
					<view class="you" v-else><image :src="baseUrl + '/wximage/yixz.png'"></image></view>
				</view>
				<view class="address clearfix">
					<image :src="baseUrl + '/wximage/dizhi.png'" class="fl"></image>
					<text class="fl">地址：{{item.full_address}}</text>
				</view>
			</view>
		</view>
		<view class="empty" v-else>
			<image :src="baseUrl + '/wximage/empty.png'"></image>
			<text>暂无相关数据</text>
		</view>
		<view class="footer clearfix">
			<view class="name fl">已选中：{{checknum}}</view>
			<view class="submit fr" @click="submit">确定</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				baseUrl: getApp().globalData.baseUrl,
				headerTop: 0,
				pHeight: 0,
				tHeight: 0,
				keywords: '',
				list: [1],
				bjstatus: false,
				keystatus: false,
				stationList: [],
				formData: {
					agentid: '',
					search: '',
				},
				checknum:0,
				checkarr:[]
			}
		},
		onLoad() {
			console.log("asj12341234")
			// 头部距离
			let res = uni.getSystemInfoSync() ///微信api方法
			let titleH;
			if (res && res['system']) {
				// 判断是否是安卓操作系统 （标题栏苹果为44px,安卓为48px）
				if (res['system'].indexOf('Android') > 0) {
					titleH = 48
				} else {
					titleH = 46
				}
				this.headerTop = titleH + res['statusBarHeight']
				this.pHeight = titleH
				this.tHeight = res['statusBarHeight']
			}
			
			this.formData.agentid = uni.getStorageSync('agent_id');
			this.getstationallocation();
			
		},
		methods: {
			//门店的id
			dianji(item,key){
				//查看是否选中 如果是false变为true 并存储到数组
				if(item.checked == false){
					this.stationList[key].checked = true;
					this.checknum = this.checknum+1;
					this.checkarr.push(item.id);
				}else{
					this.stationList[key].checked = false;
					this.checknum = this.checknum-1;
					for(let i=0;i<this.checkarr.length;i++){
						if(this.checkarr[i] == item.id){
							this.checkarr.splice(i);
						}
					}
				}	
			},
			//把门店分配给
			submit(){
				if(this.checknum > 0){
					uni.redirectTo({
						url: '/subpackageA/store/alloctionliebiao?arrstation='+JSON.stringify(this.checkarr)
					});
				}else{
					uni.showToast({
						title: '请选择门店',
						icon: 'none'
					})
				}
			},
			
			getstationallocation(){
				this.request({
					url: '/agent/stationallocationlist',
					data: this.formData,
					method: "GET"
				}).then(res => {
					if (res.data.code == 200) {
						if(res.data.data!=null){
							this.stationList = this.stationList.concat(res.data.data.stationlist);
						}
					} else {
						uni.showToast({
							title: res.data.message,
							icon: 'none'
						})
					}
				})
			},
			
			search(){
				this.stationList = [];
				this.checknum = 0;
				this.checkarr = [];
				
				this.getstationallocation();
			},
			
			keytankuang(){
				this.bjstatus = true;
				this.keystatus = true;
			},
			
			guanbi(){
				this.bjstatus = false;
				this.keystatus = false;
			},
			fanhui() {
				uni.navigateBack();
			}
		}
	}
</script>

<style lang="scss" scoped>
	.store {
		width: 100%;
		margin: 0 auto;
		height: 100vh;
		background: #f9f9ff;
		overflow-y: scroll;

		.head {
			width: 100%;
			position: fixed;
			top: 0;
			left: 0;
			z-index: 99;
			background: linear-gradient(90deg, #f9f9ff, #d4e8ff);

			.xztitle {
				position: fixed;
				left: 0%;
				top: 0;
				width: 100%;
				text-align: left;
				color: #333333;
				font-size: 32rpx;
				padding-left: 74rpx;
				font-weight: 700;

				text {
					font-size: 24rpx;
				}

				.iconfont {
					position: absolute;
					top: 0;
					left: 30rpx;
					font-size: 44rpx;
				}
			}
		}

		.headtop {
			width: 100%;
			background: linear-gradient(90deg, #f9f9ff, #d4e8ff);
			height: 220rpx;
			position: relative;
			
			.sousuo{
				width: 100%;
				padding: 30rpx 40rpx 20rpx;
				box-sizing: border-box;
				
				.left{
					height: 60rpx;
					line-height: 60rpx;
					
					.name{
						color: #666666;
					}
					
					image{
						width: 44rpx;
						height: 44rpx;
						margin-top: 8rpx;
					}
				}
				
				.right{
					width: 100%;
					position: relative;
					
					input{
						width: 100%;
						height: 60rpx;
						line-height: 60rpx;
						background: #ffffff;
						border-radius: 30rpx;
						padding-left: 30rpx;
						color: #999999;
					}
					
					image{
						width: 72rpx;
						height: 40rpx;
						position: absolute;
						right: 10rpx;
						top: 10rpx;
						z-index: 10;
					}
				}
			}
		}
		
		.shuju{
			width: 100%;
			padding: 30rpx 20rpx;
			box-sizing: border-box;
			margin-top: -130rpx;
			
			.li{
				width: 100%;
				position: relative;
				background: #fff;
				border-radius: 20rpx;
				margin-bottom: 20rpx;
				padding: 30rpx 28rpx;
				box-shadow: rgba(223, 230, 255, 0.67) 0px 0px 6px;
				
				image{
					width: 100rpx;
					height: 100rpx;
				}
				
				.cen{
					width: 390rpx;
					margin-left: 20rpx;
					
					text{
						display: block;
					}
					
					.title{
						font-size: 28rpx;
						color: #333333;
						font-weight: 700;
						margin-bottom: 8rpx;
					}
					
					.shebei{
						font-size: 22rpx;
						color: #3B91F8;
					}
				}
				
				.you{
					position: absolute;
					top: 54rpx;
					right: 50rpx;
					
					image{
						width: 40rpx;
						height: 40rpx;
					}
				}
				
				.address{
					margin-top: 10rpx;
					
					image{
						width: 30rpx;
						height: 30rpx;
						margin-top: 4rpx;
					}
					
					text{
						display: inline-block;
						line-height: 32rpx;
						font-size: 24rpx;
						color: #666666;
						width: 90%;
					}
				}
				
				.addressts{
					
					text{
						width: 62%;
					}
				}
				
				.bili{
					position: absolute;
					right: 28rpx;
					bottom: 30rpx;
					width: 180rpx;
					height: 60rpx;
					line-height: 60rpx;
					text-align: center;
					background: #3B91F8;
					color: #FFFFFF;
					border-radius: 16rpx;
					font-size: 28rpx;
				}
			}
		}
		
		.empty {
			width: 100%;
			margin: 200rpx auto 0;
			text-align: center;
		
			image {
				width: 390rpx;
				height: 340rpx;
			}
		
			text {
				display: block;
				margin-top: 60rpx;
				font-size: 24rpx;
				color: #666666;
			}
		}
		
		.footer{
			width: 100%;
			margin: 0 auto;
			height: 72rpx;
			position: fixed;
			bottom: 0;
			left: 0;
			padding: 0 60rpx;
			box-sizing: border-box;
			
			.name{
				height: 72rpx;
				line-height: 72rpx;
				font-size: 32rpx;
				color: #333333;
			}
			
			.submit{
				width: 240rpx;
				height: 72rpx;
				line-height: 72rpx;
				background: linear-gradient(90deg, #65bdfc, #398ef8);
				border-radius: 36rpx;
				border-top-left-radius: 0;
				border-bottom-left-radius: 42rpx;
				color: #FFFFFF;
				font-size: 32rpx;
				text-align: center;
			}
		}

		.beijing{
			position: absolute;
			top: 110rpx;
			left: 0;
			width: 100%;
			height: 90vh;
			background: #000000;
			opacity: 0.5;
			z-index: 100;
		}
		
		.tankuang{
			position: absolute;
			top: 110rpx;
			left: 0;
			width: 100%;
			height: 320rpx;
			background: #fff;
			overflow-y: scroll;
			z-index: 200;
			border-bottom-left-radius: 20rpx;
			border-bottom-right-radius: 20rpx;
			padding: 20rpx 0;
			
			.liebiao{
				width: 100%;
				height: 72rpx;
				line-height: 72rpx;
				text-align: center;
				position: relative;
				
				.wenzi{
					font-size: 24rpx;
					color: #999999;
				}
				
				image{
					width: 100%;
					height: 72rpx;
					position: absolute;
					top: 0;
					left: 0;
				}
			}
		}
	}
</style>